/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jlibrarian;

import java.util.Calendar;
import java.util.Collection;
import javax.sql.DataSource;
import jlibrarian.entities.Customer;
import jlibrarian.interfaces.BookManager;
import jlibrarian.entities.Book;
import jlibrarian.entities.Rent;
import jlibrarian.interfaces.CustomerManager;
import jlibrarian.interfaces.RentManager;


/**
 *
 * @author dandelion8
 */
public class Main {
    

    
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args){
        
        //create connection
        DataSource ds = DbManager.getDataSource();
        //--------------------------------------//
        
        DbManager man = new DbManager(DbManager.getDataSource());
        man.createAllTables();
        return;
        /*
        CustomerManager cm = new CustomerManagerImpl(ds);
        RentManager rm = new RentManagerImpl(ds);
        BookManager bm = new BookManagerImpl(ds);
        
        System.out.println("CREATING RENT:");
        Customer found = cm.findCustomerById(15);
        if(found != null)
        {
            System.out.println(found.getFirstName() + " " + found.getSurname() + ", tel: " + found.getTelephone());            
            
            Book b = new Book("Nejaka kniha", "Nejaky autor", 2, "");
            b = bm.createBook(b);
            
            Calendar toReturn = Calendar.getInstance();
            toReturn.add(Calendar.MONTH, 1);
            Rent r = new Rent(found, b, Calendar.getInstance(), toReturn);
            
            System.out.println("Creating a rent: " + rm.createRent(r).getRid());
        }
        
        
        
        Collection<Customer> found2 = cm.findCustomerByNames(null, "Ma%");
        for(Customer c : found2)
        {
            System.out.println(c.getFirstName() + " " + c.getSurname() + ", tel: " + c.getTelephone());            
        }
        
        // TODO code application logic here
        
        System.out.println("CREATING BOOK:");
        
        Book b = new Book("manicka", "tux", 2, "poznamka");
        
        b.setBid(6);
        
        b = bm.createBook(b);
        System.out.println(b.getBid());
        
        
        System.out.println("UPDATE BOOK:");
        //----------------------updateBook---------------------------//
        Book bOK1;
        bOK1 = new Book();
        bOK1.setAuthors("Jenda Plechovec");
        bOK1.setQuantity(12);
        bOK1.setTitle("Viktorka na splavu");
        bOK1.setNote("Je to o nicem");
        
        Book res = bm.createBook(bOK1);
        
        System.out.println("returned author: "+res.getAuthors());
        res.setAuthors("modified author");
        
        boolean updated = bm.updateBook(res);
        System.out.println("updated? "+updated);
        
        System.out.println("updated authors: "+bm.findBookById(res.getBid()).getAuthors());
    
        
        
        
       
        Book bOK2;
        Book bOK3;
        
        bOK1 = new Book();
        bOK1.setAuthors("Jenda Plechovec");
        bOK1.setQuantity(12);
        bOK1.setTitle("Viktorka na splavu");
        bOK1.setNote("Je to o nicem");

        bOK2 = new Book();
        bOK2.setAuthors("karel polacek");
        bOK2.setQuantity(3);
        bOK2.setTitle("bylo nas 5");
        bOK2.setNote("");
        
        bOK3 = new Book();
        bOK3.setAuthors("karel polacek");
        bOK3.setQuantity(9);
        bOK3.setTitle("stara blazena");
        bOK3.setNote("poznamka");
        
        bm.createBook(bOK3);
        bm.createBook(bOK2);
        bm.createBook(bOK1);
        
        System.out.println("FOUND BOOKS BY AUTHORS:");
        
        Collection<Book> foundC = bm.findBooksByAuthors("karel polacek");
        for(Book b4 : foundC){
            System.out.println(b4.getBid() + " " + b4.getAuthors() + " " + b4.getTitle());
        }*/
    }

}
